package com.wxn.learncompose.pagers

import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.Card
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
import com.wxn.learncompose.MyApp
import com.wxn.learncompose.widget.NoRipperIconButton

@Composable fun FAB_Icon_IconButton() {

    var showMoreBtn = remember {
        mutableStateOf(false)
    }
    var favoriteColorCheck = remember {
        mutableStateOf(false)
    }

    Surface {
        Column(
            modifier = Modifier
                .padding(12.dp, 18.dp)
                .fillMaxWidth()
                .fillMaxHeight(),
            verticalArrangement = Arrangement.Bottom,
            horizontalAlignment = Alignment.End
        ) {
            Box(
                modifier = Modifier
                    .fillMaxWidth(1.0f)
                    .weight(1f, true) //指定占用父控件剩余控件的多少份额，这里相当于全部占用
            ) {
                //3个IconButton， 并列排放
                Column(
                    modifier = Modifier.padding(8.dp, 12.dp),
                    verticalArrangement = Arrangement.Top,
                    horizontalAlignment = Alignment.Start
                ) {
                    Row(
                        modifier = Modifier.padding(0.dp),
                        verticalAlignment = Alignment.Top,
                        horizontalArrangement = Arrangement.Start
                    ) {
                        IconButton(onClick = {
                            Toast.makeText(MyApp.context(), "search", Toast.LENGTH_SHORT).show()
                        }) {
                            Icon(Icons.Filled.Search, contentDescription = "search")
                        }
                        IconButton(onClick = {
                            Toast.makeText(MyApp.context(), "search", Toast.LENGTH_SHORT).show()}) {
                            Icon(Icons.Filled.Check , contentDescription = "Check")
                        }
                        IconButton(onClick = {
                            Toast.makeText(MyApp.context(), "search", Toast.LENGTH_SHORT).show()
                        }) {
                            Icon(Icons.Filled.ArrowBack, contentDescription = "back")
                        }
                    }

                    //一个Card， 包含 去掉水波纹效果的 NoRipperIconButton
                    Card(
                        modifier = Modifier
                            .size(360.dp, 480.dp)
                            .background(Color.White, RoundedCornerShape(8.dp))
                            .shadow(elevation = 6.dp)
                    ){
                        Column(
                            modifier = Modifier.padding(0.0.dp),
                            verticalArrangement = Arrangement.Center
                        ) {
                            Box(modifier = Modifier
                                .background(Color(0XFF55EEAA))
                                .fillMaxWidth()
                                .height(150.dp),
                                contentAlignment = Alignment.Center) {
                                Text(text = "一言",
                                    textAlign = TextAlign.Center,
                                )
                            }
                            Box(modifier = Modifier
                                .padding(12.dp, 8.dp)
                                .fillMaxWidth(),
                                contentAlignment = Alignment.TopStart
                            ){
                                Text(text = "\"",
                                    fontSize = TextUnit(16f, TextUnitType.Sp),
                                    fontWeight = FontWeight.ExtraBold)
                            }
                            Text(text = "    把同班的女同学娶回家就是我最大的梦想。\n\n",
                                fontSize = TextUnit(18f, TextUnitType.Sp),
                                fontWeight = FontWeight.Normal)
                            Spacer(modifier = Modifier.height(12.dp))
                            Box(modifier = Modifier
                                .padding(12.dp, 8.dp)
                                .fillMaxWidth(),
                                contentAlignment = Alignment.BottomEnd
                            ){
                                Text(text = "\"",
                                    fontSize = TextUnit(16f, TextUnitType.Sp),
                                    fontWeight = FontWeight.ExtraBold)
                            }
                            Box(modifier = Modifier
                                .padding(0.dp)
                                .fillMaxWidth()
                                .weight(1f, fill = true),
                                contentAlignment = Alignment.BottomEnd) {
                                Row(
                                    modifier = Modifier.padding(6.dp, 16.dp),
                                ) {
                                    NoRipperIconButton(onClick = {
                                        favoriteColorCheck.value = !favoriteColorCheck.value
                                    }) {
                                        Icon(
                                            Icons.Filled.Favorite,
                                            contentDescription = "favorite",
                                            tint = if (favoriteColorCheck.value) Color.Red else Color.LightGray
                                        )
                                    }
                                    Spacer(modifier = Modifier.width(6.dp))
                                    NoRipperIconButton(onClick = {
                                        Toast.makeText(MyApp.context(), "Share", Toast.LENGTH_SHORT)
                                            .show()
                                    }) {
                                        Icon(
                                            Icons.Filled.Share,
                                            contentDescription = "Share",
                                            tint = Color.LightGray
                                        )
                                    }
                                }
                            }
                        }
                    }
                }

            }

            //点击底部的FloatingActionButton， 会显示ExtendedFloatingActionButton
            if (showMoreBtn.value) {
                ExtendedFloatingActionButton(onClick = { showMoreBtn.value = false },
                    modifier = Modifier.size(200.dp, 45.dp),
                    containerColor = Color.White,
                    contentColor = Color.Blue) {
                    Row {
                        Icon(Icons.Filled.Favorite , contentDescription = "Favorite",
                            tint = Color.Red)
                        Spacer(modifier = Modifier.size(4.dp, 1.dp))
                        Text("Add to my favorite")
                    }
                }
            }

            Spacer(modifier = Modifier.size(1.dp, 12.dp))

            FloatingActionButton(onClick = {
                showMoreBtn.value = !showMoreBtn.value
                Toast.makeText(MyApp.context(), "Click!!!", Toast.LENGTH_SHORT).show()
            },
                modifier = Modifier.padding(0.dp, 0.dp, 6.dp, 36.dp),
                shape = CircleShape,
                containerColor = Color.Blue,
                contentColor = Color.White
                ) {
                Icon(Icons.Filled.Add, contentDescription = "Favorite")
            }
        }
    }
}